/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sims.gui.salesperson;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import sims.entity.Order;
import sims.entity.User;
import sims.manager_SalesPerson.Function;

/**
 *
 * @author vanthanh
 */
public class ListSellOrder extends javax.swing.JPanel {

    /**
     * Creates new form ListOrder
     */
    DefaultTableModel model = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int i, int i1) {
            return false;
        }
    };
    String username;
   
    public ListSellOrder(String userName) {
        initComponents();
       
        this.username = userName;
        String[] column = {"Stt","OrderId","Datetime","UserId","type","Total"};
        model.setColumnIdentifiers(column);
        Function fun = new Function();
        ArrayList<Order> arrOrder = new ArrayList<Order>();
        arrOrder = fun.getAllOrder();
        int stt=0;
        for(Order o : arrOrder){
            stt++;
            Object[] row ={stt,o.getOrderID(),o.getDatetime(),o.getUserId(),o.getType(),o.getTotal()};
            model.addRow(row);
        }
        jTable_ListOrderSell.setModel(model);
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnListOrder = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        lbListOrderSell = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_ListOrderSell = new javax.swing.JTable();
        btxView = new javax.swing.JButton();

        pnListOrder.setLayout(new java.awt.BorderLayout());

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lbListOrderSell.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lbListOrderSell.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbListOrderSell.setText("List Sell Order ");
        jPanel1.add(lbListOrderSell, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 10, 421, -1));

        jTable_ListOrderSell.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable_ListOrderSell);

        jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 51, 560, 337));

        btxView.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        btxView.setText("View");
        btxView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btxViewActionPerformed(evt);
            }
        });
        jPanel1.add(btxView, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 410, 83, -1));

        pnListOrder.add(jPanel1, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnListOrder, javax.swing.GroupLayout.DEFAULT_SIZE, 605, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnListOrder, javax.swing.GroupLayout.DEFAULT_SIZE, 471, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btxViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btxViewActionPerformed
       
        if(jTable_ListOrderSell.getSelectedRow() == -1){
             JOptionPane.showMessageDialog(this, "don't select order need view");
         }else{
             int row = jTable_ListOrderSell.getSelectedRow();
             String orderId =jTable_ListOrderSell.getValueAt(row, 1).toString();
             pnListOrder.removeAll();
             ViewOrder viewOrder = new ViewOrder(orderId,username);
             pnListOrder.add(viewOrder);
             pnListOrder.validate();
         }
//        if(jTable_ListOrderSell.getSelectedRow() == -1){
//             JOptionPane.showMessageDialog(this, "don't select order need view");
//         }else{
//             int row = jTable_ListOrderSell.getSelectedRow();
//             String orderId =jTable_ListOrderSell.getValueAt(row, 1).toString();
//             ViewOrder viewOrder = new ViewOrder(orderId,username);
//             viewOrder.setVisible(true);  
//         }
    }//GEN-LAST:event_btxViewActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btxView;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable_ListOrderSell;
    private javax.swing.JLabel lbListOrderSell;
    private javax.swing.JPanel pnListOrder;
    // End of variables declaration//GEN-END:variables
}
